package com.zut.edu.utils;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 单线程线程池获取
 * @author WaterWood
 */
public class SingleLineUtils {

    private static SingleLineUtils mInstance;
    private ExecutorService singleThreadExecutor;

    public static SingleLineUtils getInstance(){
        if (mInstance == null){
            synchronized (SingleLineUtils.class){
                if (mInstance == null){
                    mInstance = new SingleLineUtils();
                }
            }
        }
        return mInstance;
    }

    private SingleLineUtils() {}

    public ExecutorService getSingle(){
        if (singleThreadExecutor == null){
            synchronized (SingleLineUtils.class){
                if (singleThreadExecutor == null){
                    singleThreadExecutor =  Executors.newSingleThreadExecutor();
                }
            }
        }
        return singleThreadExecutor;
    }
}